package cn.iocoder.yudao.module.vlog.comment.dal.mysql;

import cn.iocoder.yudao.framework.business.basic.dao.mapper.CoreMapper;
import cn.iocoder.yudao.module.vlog.comment.bo.VLogCommentBO;
import cn.iocoder.yudao.module.vlog.comment.dal.dataobject.VLogCommentDO;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 视频评论 Mapper
 *
 * @author 山野羡民（1032694760@qq.com）
 */
@Mapper
public interface VLogCommentMapper extends CoreMapper<VLogCommentDO> {

    @Select("""
            <script>
                    SELECT vi.play_url as vlogPlayUrl,
                    vi.cover_url as vlogCoverUrl,
                    vi.title as vlogTitle,
                    vc.*
                    FROM vlog_comment AS vc
                    LEFT JOIN vlog_info AS vi ON vi.id = vc.vlog_id
                    <where>
                        vi.deleted = false
                        <if test="shopId != null and shopId > 0">
                            AND vc.shopId = #{shopId}
                        </if>
                        <if test="vlogId != null and vlogId > 0">
                            AND vc.vlog_id = #{vlogId}
                        </if>
                        <if test="visible != null">
                            AND vc.visible = #{visible}
                        </if>
                    </where>
                    ORDER BY vc.liked_count DESC, vc.create_time DESC
            </script>
            """)
    Page<VLogCommentBO> selectVLogCommentPage(@Param("page") Page<VLogCommentBO> page, @Param("shopId") Long shopId, @Param("vlogId") Long vlogId, @Param("visible") Boolean visible);
    @Select("""
            <script>
                    SELECT vi.play_url as vlogPlayUrl,
                    vi.cover_url as vlogCoverUrl,
                    vi.title as vlogTitle,
                    vc.*
                    FROM vlog_comment AS vc
                    LEFT JOIN vlog_info AS vi ON vi.id = vc.vlog_id
                    <where>
                        vi.deleted = false
                        <if test="parentIds != null and parentIds.size() > 0">
                            and vi.parent_id in
                            <foreach collection="parentIds" open="(" item="parentId" separator="," close=")">
                                #{parentId}
                            </foreach>
                        </if>
                        <if test="visible != null">
                            AND vc.visible = #{visible}
                        </if>
                    </where>
                    ORDER BY vc.liked_count DESC, vc.create_time DESC
            </script>
            """)
    List<VLogCommentBO> selectVLogCommentList(@Param("parentIds") List<Long> parentIds, @Param("visible") Boolean visible);

}
